<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/17 0017
  Time: 上午 10:42
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>角色管理-添加</title>

    <link rel="stylesheet" href="/static/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/static/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">

    <link rel="stylesheet" href="/static/css/common.css">

</head>
<body>
<div class="wrap-padding-15">
    <span class="layui-breadcrumb">
          <a href="/" target="_top">首页</a>
          <a href="/role">角色管理</a>
          <a><cite>增加</cite></a>
     </span>

    <div class="box-form">
        <form action="/role/save" method="post" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="name"  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">角色状态：</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="status" value="1" title="启用">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">角色权限：</label>
                <div class="layui-input-block">
                    <input type="hidden" name="permissionIds" id="permissionIds">
                    <ul id="permi_tree" class="ztree"></ul>
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注：</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formSubmit">提交</button>
                    <a href="/role"><button type="button" class="layui-btn layui-btn-primary">取消</button></a>
                </div>
            </div>

        </form>
    </div>

</div>




<script src="/static/plugins/jquery.js"></script>
<script src="/static/plugins/layui/layui.js"></script>
<script type="text/javascript" src="/static/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="/static/plugins/ztree/js/jquery.ztree.excheck.js"></script>


<script>

    layui.use(['element','layer','form'], function(){
        var form = layui.form;

        var setting = {
            check:{
                enable:true
            },
            data:{
                simpleData:{
                    enable:true
                }
            }
        }
        $.ajax({
            url:'/role/tree',
            type:'get',
            dataType:'json',
            //data:'',
            success:function (msg) {
                if(msg.code == 1){
                    var treeNodes = msg.data;
                    $.fn.zTree.init($("#permi_tree"),setting,treeNodes)
                }else{
                    layer.msg("加载树节点失败")
                }
            },
            error:function () {
                layer.msg("加载树节点失败")
            }
        })

        //监听提交
        form.on('submit(formSubmit)',function (data) {
            var treeObj = $.fn.zTree.getZTreeObj("permi_tree");  //获取树对象
            var nodes = treeObj.getCheckedNodes(true);  //获取树的选中节点
            var idArr = [];
            $.each(nodes,function (i,item) {
                idArr.push(item.id)
            })
            $("#permissionIds").val(idArr.join(","));
            return true;
        })

    });


</script>
</body>
</html>
